class Shop:
    '''第一版'''
    def __init__(self, good:list=None):
        self.products = [
            [1, "iphone", 6888],
            [2, "MacPro", 14800],
            [3, "小米6", 2499],
            [4, "Coffee", 31],
            [5, "Book", 60],
            [6, "Nike", 699]
        ] 
        self.index = len(self.products)
        if good is not None:
            self.index += 1
            self.products.append([self.index]+good)
    
    def opening(self):
        number = ''
        shop_car = []
        while True:
            self.show_goods()
            number = input('What do you want to buy?\n').strip()
            if number == 'q':
                print('bye!')
                break
            number = int(number)
            if  number < 1 or number > self.index:
                raise Exception('滚蛋，没有这东西')
            shop_car.append(self.products[number-1])
            print(f'当前你的购物车有{shop_car}')
    
    def show_goods(self):
        print('-------------------- 商品列表 ---------------------')
        print(self.index)
        for good in self.products:    
            print('{}\t{:20}\t{}'.format(*good))
    
    def append_goods(self, good=None):
        if good is not None:
            self.index += 1
            self.products.append([self.index]+good)
        return self
    
    
shop = Shop()
shop.append_goods(['流畅的python', 80])
shop.opening()

# emmm 异常提示不是那么友好